﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace DTO
{
  
    //path representation
    [Serializable]
    public class PathTour : ICloneable
    {
        private double _fitness;
        public double Fitness
        {
            get { return _fitness; }
            set { _fitness = value; }
        }

        private int[] _orderCity;
        public int[] OrderCity
        {
          get { return _orderCity; }
          set { _orderCity = value; }
        }

        public PathTour(int numOfCity)
        {
            _orderCity = new int[numOfCity];
        }
        public object Clone()
        {
            //return this.MemberwiseClone();
            using (MemoryStream ms = new MemoryStream())
            {
                IFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, this);
                ms.Position = 0;
                return bf.Deserialize(ms);
            }
        }

       
    }

    //order representation
    public class Adjacency : ICloneable
    {
        private double _fitness;
        public double Fitness
        {
            get { return _fitness; }
            set { _fitness = value; }
        }
        private int[] _orderCity;
        public int[] OrderCity
        {
            get { return _orderCity; }
            set { _orderCity = value; }
        }

        public Adjacency(int numOfCity)
        {
            _orderCity = new int[numOfCity];
        }

        public object Clone()
        {
            //return this.MemberwiseClone();
            using (MemoryStream ms = new MemoryStream())
            {
                IFormatter bf = new BinaryFormatter();
                bf.Serialize(ms, this);
                ms.Position = 0;
                return bf.Deserialize(ms);
            }
        }

    }
    
    //Sap xep tang dan theo fitness
    public class SortAscFitnessPathTour : IComparer<PathTour>
    {            
        public int Compare(PathTour x, PathTour y)
        {          
            if (x.Fitness > y.Fitness)
            {
                return 1;
            }
            else
            {
                if (x.Fitness < y.Fitness)
                {
                    return -1;
                }
                else
                {
                    return 0;
                }
            }
        }
    }

}
